<%@ page import="com.qimei.onerice.entity.Order" %>
<%@ page import="com.qimei.onerice.service.impl.OrderDetailServiceImpl" %>
<%@ page import="com.qimei.onerice.entity.OrderDetail" %>
<%@ page import="java.util.List" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Liubuzhu
  Date: 2023/12/11
  Time: ฅ(΅•ㅅ•΅❀)ฅ 14:55
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" pageEncoding="UTF-8" language="java" %>
<%-- <script src="<c:url value="/js/jquery.min.js"/>"></script> --%>
<%-- <script> --%>
<%-- 	// 解决无法使用下拉框问题 --%>
<%-- 	let $j = jQuery.noConflict(); --%>
<%-- </script> --%>
<link rel="stylesheet" href="<c:url value="/css/bootstrap.min.css"/>">
<script src="<c:url value="/js/bootstrap.bundle.min.js"/>"></script>
<header>
	<div class="px-3 py-2 text-bg-dark">
		<div class="container">
			<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
				<a href="<c:url value="/view/home.jsp"/>" class="d-flex align-items-center my-2 my-lg-0 me-lg-auto text-white text-decoration-none">
					<img src="<c:url value="/img/common/onerice.png"/>" height="60px">
				</a>

				<ul class="nav col-12 col-lg-auto my-2 justify-content-center my-md-0 text-small" >
					<li>
						<a href="<c:url value="/view/home.jsp"/>" class="nav-link text-white" >
							<img class="bi d-block mx-auto mb-1" src="<c:url value="/img/common/home.png"/>" width="24px" height="24px">
							首页
						</a>
					</li>
					<li>
						<a href="<c:url value="/view/store.jsp"/>" class="nav-link text-white">
							<img class="bi d-block mx-auto mb-1" src="<c:url value="/img/common/store.png"/>" width="24px" height="24px">
							商店
						</a>
					</li>
					<c:if test="${not empty sessionScope.user}">
						<%
							Order order = (Order)session.getAttribute("order");
							int size = 0;
							if (order != null) {
								List<OrderDetail> orderDetailList = new OrderDetailServiceImpl().getOrderDetailListByOrderId(order.getOrderId());
								size = orderDetailList.size();
							}
							pageContext.setAttribute("size", size);
						%>

						<!-- 用户登录时 -->
						<li>
							<a href="<c:url value="/view/cart.jsp"/>" class="nav-link text-white">
								<img class="bi d-block mx-auto mb-1" src="<c:url value="/img/common/cart.png"/>" width="24px" height="24px">
								购物车 <span class="badge badge-danger">${size}</span>
							</a>
						</li>
					</c:if>
					<c:if test="${empty sessionScope.user}">
						<!-- 用户未登录时 -->
						<li>
							<a href="<c:url value="/login.jsp"/>" class="nav-link text-white">
								<img class="bi d-block mx-auto mb-1" src="<c:url value="/img/customer/user.png"/>" width="24px" height="24px" alt="login">
								登录
							</a>
						</li>
					</c:if>
					<c:if test="${not empty sessionScope.user}">
						<!-- 用户已登录时 -->
						<li class="nav-item dropdown">
							<a class="nav-link dropdown-toggle text-white" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
								<img class="bi d-block mx-auto mb-1" src="<c:url value="/img/customer/${sessionScope.user.customerImage}"/>" width="24px" height="24px" alt="user">
								个人中心
							</a>
							<ul class="dropdown-menu text-small">
								<li><a class="dropdown-item" href="<c:url value="/view/customerInfo.jsp"/>">个人信息</a></li>
								<li><a class="dropdown-item" href="<c:url value="/view/updatePassword.jsp"/>">修改密码</a></li>
								<li><hr class="dropdown-divider"></li>
								<li><a class="dropdown-item" href="<c:url value="/logout.jsp"/>">退出登录</a></li>
							</ul>
						</li>
					</c:if>
				</ul>
			</div>
		</div>
	</div>
</header>
